package by.andronix.logger
{
	import flash.external.ExternalInterface;
	
	import mx.core.mx_internal;
	import mx.logging.targets.LineFormattedTarget;
	
	use namespace mx_internal;
	
	public class FirebugTarget extends LineFormattedTarget
	{
		public function FirebugTarget()
		{
			super();
		}
	
	    override mx_internal function internalLog(message:String):void
	    {
	        if (ExternalInterface.available) {
	        	var fbMethod:String = message.match(/\[(WARN|ERROR|FATAL|DEBUG|INFO)\]/)[1];
	        	fbMethod = fbMethod.toLowerCase();
	        	
	        	fbMethod = fbMethod == 'fatal' ? 'error' : fbMethod;
	        	
	        	ExternalInterface.call("function(msg){if (console && console."+fbMethod+") console."+fbMethod+"('', msg)}", message);
	        	
	        }
	        	
	    }
		
	}
}